/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tuan02;

/**
 *
 * @author XuanHung
 */

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.imageio.stream.FileImageOutputStream;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author XuanHung
 */

public class clsHocSinh {
    private String m_strHoTen = new String();
    private float m_fToan;
    private float m_fVan;
    private float m_fTrungBinh;
    
    
    public void setHoTen(String _strTen){
        m_strHoTen = _strTen;
    }
    public String getHoTen(){
        return m_strHoTen;
    }
    
    public void setToan(float _fToan){
        m_fToan = _fToan;
    }
    
    public float getToan(){
        return m_fToan;
    }
    
    public void setVan(float _fVan){
        m_fVan = _fVan;
    }
    public float getVan(){
        return m_fVan;
    }
    
    public void setDTB(float _fDTB){
        m_fTrungBinh = _fDTB;
    }
    
    public float getDTB(){
        return m_fTrungBinh;
    }
    
    public clsHocSinh(){
        m_fToan =  0;
        m_fVan = 0;
        m_fTrungBinh = 0;
    }
    public clsHocSinh (float _fToan, float _fVan){
        m_fToan = _fToan;
        m_fVan = _fVan;
        m_fTrungBinh = TrungBinh(_fToan,  _fVan);
    }
    public clsHocSinh (String _strHoTen, float _fToan, float _fVan, float _fTB){
        m_strHoTen = _strHoTen;
        m_fToan = _fToan;
        m_fVan = _fVan;
        m_fTrungBinh = _fTB;
    }
    static private float TrungBinh(float _fToan, float _fVan){
        return (_fToan + _fVan)/2;
    }
    
    
    static private void NhapHocSinh(clsHocSinh hs){
        hs = new clsHocSinh();
        Scanner sn = new Scanner(System.in);
        System.out.println("Nhap Ten:");
        hs.m_strHoTen = sn.nextLine();
        System.out.println("Nhap Diem Toan");
        hs.m_fToan = Float.parseFloat(sn.nextLine());
        System.out.println("Nhap Diem Van");
        hs.m_fVan = Float.parseFloat(sn.nextLine());
        hs.m_fTrungBinh = TrungBinh(hs.m_fToan, hs.m_fVan);
    }
    public static void NhapHocSinh(int n) throws FileNotFoundException{
        FileOutputStream fos = new  FileOutputStream("dulieu_hosinh.txt", true);
        PrintWriter fw = new PrintWriter(fos);
        fw.println(n);
        clsHocSinh [] hs;
        hs = new clsHocSinh[n];
        for(int t = 0; t < n; t++){
            NhapHocSinh(hs[t]);
            fw.println(hs[t].getHoTen() + "\t" + hs[t].getToan() + "\t" + hs[t].getVan() + "\t" + hs[t].getDTB());
        }
    }
    public void XuatHocSinh(){
        //System.out.println("Diem toan");
        System.out.println("Hoc Ten Hoc Sinh" + this.getHoTen());
        System.out.println("Diem toan" + this.getToan());
        System.out.println("Diem van" + this.getVan());
        System.out.println("Diem trung Binh" + this.getDTB());
    }
    public static void DocHocSinhvaXuat() throws FileNotFoundException, IOException{
        clsHocSinh hs;
        
        FileReader fr= new FileReader("dulieu_hocsinh.txt");
        BufferedReader input= new BufferedReader(fr);
        int n;
        n = Integer.parseInt(input.readLine());
        String [] str;
        for(int i = 1; i <= n; i++){
            str = input.readLine().split("\t");
            hs = new clsHocSinh(str[0], Float.parseFloat(str[1]),Float.parseFloat(str[2]),Float.parseFloat(str[3]));
            hs.XuatHocSinh();
        }
                
    }
    
}

